package com.gjun.struts.action;

import java.util.Date;
import java.util.List;

import com.gjun.struts.bean.GjunRoleJsonBean;
import com.gjun.struts.bean.GjunsystemUserJsonBean2;
import com.gjun.struts.resource.GjunRoleResourceIf;
import com.gjun.struts.resource.GjunSystemUserResourceIf;
import com.gjun.struts.util.JSONHelper;

public class MgrSystemUserAction {

	private String result;

	private String roles_json;

	// 用于设置分页参数
	private int pageSize = 10; 
								

	private int totalSize;

	private int totalPage;

	private int curPage;
	
	// 用于传递参数
	private String checkType;   // 查询方式
	
	private String username;    // 假如是基本查询就接收用户名
	
	// 假如是复杂查询就接受4样信息
    private String state;
    
    private String role;
    
    private Date starttimer;
    
    private Date endtimer;
    
    
    // dao

	private GjunRoleResourceIf roleResource;
	
	private GjunSystemUserResourceIf userResource;
	
	

	
	
	public GjunSystemUserResourceIf getUserResource() {
		return userResource;
	}

	public void setUserResource(GjunSystemUserResourceIf userResource) {
		this.userResource = userResource;
	}

	public String getCheckType() {
		return checkType;
	}

	public void setCheckType(String checkType) {
		this.checkType = checkType;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public Date getEndtimer() {
		return endtimer;
	}

	public void setEndtimer(Date endtimer) {
		this.endtimer = endtimer;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public Date getStarttimer() {
		return starttimer;
	}

	public void setStarttimer(Date starttimer) {
		this.starttimer = starttimer;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getRoles_json() {
		return roles_json;
	}

	public void setRoles_json(String roles_json) {
		this.roles_json = roles_json;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public GjunRoleResourceIf getRoleResource() {
		return roleResource;
	}

	public void setRoleResource(GjunRoleResourceIf roleResource) {
		this.roleResource = roleResource;
	}

	public String initSelectOptionData() {
		try {
			List<GjunRoleJsonBean> beans = roleResource.loadAllRoles();
			roles_json = JSONHelper.roleToJson(beans);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			roles_json = "rolesLoaderFaild";
		}
		return "success";
	}

	public String loadSystemUserByCondition() {
		
	    //System.out.println("aaaaaaaaaaaaaaaaaaa");
		if("basicCheck".equals(checkType)){
			System.out.println("basicCheck");
	         totalSize = userResource.loadUserCountByConditionForName(username);
	         totalPage = (totalSize + pageSize -1 )/pageSize;
	         if(curPage==0) curPage=1;
	         int start = (curPage-1) * pageSize;
	         
	         List<GjunsystemUserJsonBean2> beans = userResource.loadUserByConditionForName(username, start,pageSize);
	         try {
				result = JSONHelper.usersToJson2(beans);
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				result = null;
			}
		}
		return "success";
	}
}
